<?php
require_once '../application/library/db/gcDaoFactory.php';
require_once '../application/library/helper/amountHelper.php';
require_once '../application/constant/daoConfig.php';

/**
 * 商品一览Service
 * 商品管理
 * @author    Suda
 * @version   1.0
 */
class goods_services_goodsListService {

    private $objDaoFactory;
    public function __construct() {
        $this->objDaoFactory = gcDaoFactory::getInstance();
    }

    public function pbGetCount() {
        $objGoodsDao = $this->objDaoFactory->createDao(daoConfig::T_EC_M_GOODS_DAO);
        $count = $objGoodsDao->pbGetCount();
        return $count;
    }

    public function pbGetGoods() {
        $objGoodsDao = $this->objDaoFactory->createDao(daoConfig::T_EC_M_GOODS_DAO);
        $arrGoods = $objGoodsDao->pbGetGoods();
        foreach($arrGoods as $key => &$value) {
            $value["SIMVARIATION"] = mb_substr($value["VARIATION"], 0, 10, "utf-8");
            $value["SIMNAME_GROUP"] = mb_substr($value["NAME_GROUP"], 0, 10, "utf-8");
            if($value["SUPPLIERNUM"] == null) {
                $value["SUPPLIERNUM"] = 0;
            }
        }
        return $arrGoods;
    }

    public function pbGetSearchCount($arrCondition) {
        $objGoodsDao = $this->objDaoFactory->createDao(daoConfig::T_EC_M_GOODS_DAO);
        $count = $objGoodsDao->pbGetSearchCount($arrCondition);
        return $count;
    }

    public function pbSearchGoods($arrCondition) {
        $objGoodsDao = $this->objDaoFactory->createDao(daoConfig::T_EC_M_GOODS_DAO);
        $arrGoods = $objGoodsDao->pbSearchGoods($arrCondition);
        foreach($arrGoods as $key => &$value) {
            $value["SIMVARIATION"] = mb_substr($value["VARIATION"], 0, 10, "utf-8");
            $value["SIMNAME_GROUP"] = mb_substr($value["NAME_GROUP"], 0, 10, "utf-8");
            if($value["SUPPLIERNUM"] == null) {
                $value["SUPPLIERNUM"] = 0;
            }
        }
        return $arrGoods;
    }
}